using System.Collections;
using UnityEngine;

public class UIMoveFromToAnimation : UIAnimationElement
{
	public Vector3 moveFrom;

	public Vector3 moveTo;

	public float duration;

	public bool useCurve;

	public AnimationCurve curve;

	public Transform transformToChange;

	protected Coroutine myCoroutine;

	public Transform myTransform
	{
		get
		{
			return transformToChange ?? base.transform;
		}
	}

	public override void Play()
	{
		Stop();
		base.Play();
		myCoroutine = StartCoroutine(DoAnimateIn());
	}

	public override void Stop()
	{
		base.Stop();
		if (myCoroutine != null)
		{
			StopCoroutine(myCoroutine);
		}
	}

	private IEnumerator DoAnimateIn()
	{
		float time = 0f;
		while (time < duration)
		{
			time += RealTime.deltaTime;
			float normTime = time / duration;
			if (useCurve)
			{
				normTime = curve.Evaluate(normTime);
			}
			myTransform.localPosition = Vector3Ex.LerpNotClamped(moveFrom, moveTo, normTime);
			yield return null;
		}
		myTransform.localPosition = moveTo;
		OnEnd();
	}
}
